package com.digicom.api.config;

import com.digicom.common.constant.Constants;
import com.digicom.common.entity.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 模拟配置类，仅用于开发和测试环境
 */
@Configuration
@ConditionalOnProperty(name = "spring.profiles.active", havingValue = "dev")
public class MockConfig {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 创建模拟用户数据并存入Redis
     */
    @Bean
    public boolean initMockUser() {
        // 创建模拟用户
        User user = new User();
        user.setUserId(1L);
        user.setUsername("admin");
        user.setNickname("管理员");
        user.setUserType(Constants.USER_TYPE_ADMIN);
        user.setStatus(Constants.USER_STATUS_NORMAL);
        user.setAvatar("/profile/avatar/default.jpg");
        user.setEmail("admin@example.com");
        user.setPhonenumber("13800138000");
        user.setSex("0");
        user.setLoginIp("127.0.0.1");
        user.setLoginDate(new Date());
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        user.setRemark("模拟用户");
        user.setDelFlag("0");

        // 存入Redis
        String userKey = Constants.LOGIN_USER_KEY + ":1";
        redisTemplate.opsForValue().set(userKey, user);
        
        return true;
    }
} 